package com.currency.task;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class VideoConference implements Runnable {
	private int mContainer = 0;

	public VideoConference(int mContainer) {
		super();
		this.mContainer = mContainer;
		mLatch = new CountDownLatch(mContainer);
	}

	private CountDownLatch mLatch;

	public void arrive(Pariant pariant) {
		if (null == pariant) {
			return;
		}
		String name = pariant.getName();

		System.out.printf("the current arriver is %s and time is %4d \n", name,
				System.currentTimeMillis());
		mLatch.countDown();
	}

	@Override
	public void run() {
		try {
			if (mLatch.getCount() == 1) {
				mLatch.await(1, TimeUnit.MILLISECONDS);
			} else {
				mLatch.await();
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.printf("the meeting is starting at %4ds \n",
				System.currentTimeMillis());

	}

}
